<?php

class Antz_Form_Components_Checkbox extends Antz_Form_Component
{
    public function __construct($name, $label, $value, $checked=false, $aftertext=''){
        $this->name = $name;
        $this->value = $value;
        $this->label = $label;
        $this->checked = $checked;
        $id = 'checkbox'.rand();
        $this->setId($id);
        $this->isXhtml(false);
        $this->aftertext = $aftertext;
    }

    public function render(){
    	global $gCms;
     	$Antz = Antz::registry('Antz');
     	if($this->required) $required = '<span class="required"><img src="'.$gCms->config['root_url'].'/modules/Antz/images/required.gif" alt="'.$Antz->Lang('required').'" /></span>'.$this->aftertext;
    	else $required = '';
        $closeTag = $this->isXhtml() ? '/>' : '>';
        $checked = ($this->checked) ? 'checked' : '';
        return "\n    ".$required.'<label for="'.$this->getId().'"><input type="checkbox" name="'.$this->name.'" value="'.$this->value.'" '.$this->renderParameters().' id="'.$this->getId().'" '.$checked.$closeTag.''.$this->label.''.$this->aftertext.'</label>';
    }
}
